﻿Public Class frmWeb

    Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim url As String = ""
        Dim extrae As String
        Dim fechahora As String
        Dim codeva, pilotid, flightnum, depicao, arricao, route, aircraft As String
        Dim distance, load, fuelused, fuelunitcost, fuelprice_rep, flighttype As String



        '0 callsign:  1 cid: 2 realname: 3 clienttype: 4 frequency:
        '5 latitude:  6 longitude: 7 altitude: 8 groundSpeed: 9 planned_aircraft: 10 planned_tascruise:
        '11 planned_depairport: 12 planned_altitude: 13 planned_destairport: 14 server: 15 protrevision:
        '16 rating: 17 transponder: 18 facilitytype: 19 visualrange: 20 planned_revision: 21 planned_flighttype: 
        '22 planned_deptime: 23 planned_actdeptime: 24 planned_hrsenroute: 25 planned_minenroute: 
        '26 planned_hrsfuel: 27 planned_minfuel: 28 planned_altairport: 29 planned_remarks: 30 planned_route:
        '31 planned_depairport_lat: 32 planned_depairport_lon: 33 planned_destairport_lat:
        '34 planned_destairport_lon: 35 atis_message: 36 time_last_atis_received: 37 time_logon: 38 heading:
        '39 QNH_iHg: 40 QNH_Mb

        fuelused = Trim(Str(Int((Val(frmPrincipal.lblCombustibleInicial.Text) - Val(frmPrincipal.lblCombustible.Text)) + 0.5)))
        distance = Int(Val(frmPrincipal.lblNMRecorridas.Text) + 0.5).ToString

        If esVueloVatsim Then
            url = "http://evna.vawiki.org/action.php/MvsReporteVatsim/getVatsimBB?Id=" & cnfVATSIM
            url += "&callSign=" + datosVatsim.getDatos(0)
            url += "&type=" + datosVatsim.getDatos(21)
            url += "&depIcao=" + datosVatsim.getDatos(11)
            url += "&aircraft=" + datosVatsim.getDatos(9)
            url += "&arrIcao=" + datosVatsim.getDatos(13)
            url += "&fuel=" + fuelused
            url += "&altIcao=" + datosVatsim.getDatos(28)
            url += "&fuelType=K"
            url += "&lanIcao=" + datosVatsim.getDatos(13)
            If conReserva = True Then ' vuelo con Reserva
                flightnum = flightNumber.Substring(3).PadLeft(4, "0")
            Else 'Vuelo sin Reserva
                flightnum = flightNumber
            End If
            url += "&flightNumber=" + flightnum
            url += "&distance=" + distance
            url += "&tas=" + datosVatsim.getDatos(10)
            url += "&altitude=" + datosVatsim.getDatos(12)

            If dateIVAO = "" Then dateIVAO = "23-02-196007:00:00"
            fechahora = dateIVAO.Substring(0, 2) & dateIVAO.Substring(3, 2) & dateIVAO.Substring(6)
            url += "&fecha=" & fechahora.Substring(0, 8)
            url += "&horaDep=" & fechahora.Substring(8, 5)
            If dateIVAO2 = "" Then dateIVAO2 = "23-02-196007:00:10"
            fechahora = dateIVAO2.Substring(0, 2) & dateIVAO2.Substring(3, 2) & dateIVAO2.Substring(6)
            url += "&horaArr=" & fechahora.Substring(8, 5)

            url += "&route=" + datosVatsim.getDatos(30)
            url += "&comentarios=" + datosVatsim.getDatos(29)

        End If
        If esVueloIvao Then

            pilotid = cnfPiloto.Substring(3, 3)
            'code = cnfPiloto.Substring(0, 3)

            url = cnfmvsUrlIVAO
            codeva = cnfmvsVAId

            url += "?va_id=" & codeva
            url += "&ivao_piloto_id=" & cnfIVAO
            url += "&identificativo=" & pilotid

            Dim objIniFile As New IniFile(cnfpathIvap & "\flights\default.fpl")
            extrae = objIniFile.GetString("FLIGHTPLAN", "RULES", "")
            flighttype = extrae
            url += "&reglas=" & flighttype

            extrae = objIniFile.GetString("FLIGHTPLAN", "ACTYPE", "")
            url += "&avion=" & extrae


            url += "&fuel=" & fuelused

            fuelunitcost = fuelprice
            fuelprice_rep = importefuel
            load = pax

            If conReserva = True Then ' vuelo con Reserva
                aircraft = registro
                flightnum = flightNumber.Substring(3).PadLeft(4, "0")
                url += "&numero=" & flightnum
            Else 'Vuelo sin Reserva
                aircraft = datosIvao.getDatos(9)
                'extrae = objIniFile.GetString("FLIGHTPLAN", "NUMBER", "")
                flightnum = flightNumber
                url += "&numero=" & flightnum
            End If
            'extrae = objIniFile.GetString("FLIGHTPLAN", "NUMBER", "")
            'flightnum = extrae
            'url += "&numero=" & flightnum

            extrae = objIniFile.GetString("FLIGHTPLAN", "DEPICAO", "")
            depicao = extrae
            url += "&depicao=" & depicao

            extrae = objIniFile.GetString("FLIGHTPLAN", "DESTICAO", "")
            arricao = extrae
            url += "&desticao=" & arricao

            extrae = objIniFile.GetString("FLIGHTPLAN", "ALTICAO", "")
            url += "&alticao=" & extrae


            url += "&distancia=" & distance

            extrae = objIniFile.GetString("FLIGHTPLAN", "SPEED", "")
            url += "&tas=" & extrae
            extrae = objIniFile.GetString("FLIGHTPLAN", "LEVEL", "")
            If extrae = "0" Or extrae = "" Then extrae = "1000"
            url += "&fl=" & extrae

            If dateIVAO = "" Then dateIVAO = "23-02-196007:00:00"
            fechahora = dateIVAO.Substring(0, 2) & dateIVAO.Substring(3, 2) & dateIVAO.Substring(6)
            url += "&fecha=" & fechahora.Substring(0, 8)
            url += "&hora_salida=" & fechahora.Substring(8, 5)
            If dateIVAO2 = "" Then dateIVAO2 = "23-02-196007:00:10"
            fechahora = dateIVAO2.Substring(0, 2) & dateIVAO2.Substring(3, 2) & dateIVAO2.Substring(6)
            url += "&hora_llegada=" & fechahora.Substring(8, 5)

            extrae = objIniFile.GetString("FLIGHTPLAN", "ROUTE", "")
            route = extrae
            url += "&comentarios=" & route
            'CESAR: landingrate
            'url += "&landingrate=" & landingrate.ToString


        End If
        Try
            WebBrowser.Navigate(New Uri(url))
            WebBrowser.Refresh(WebBrowserRefreshOption.Completely)
        Catch ex As System.UriFormatException
            If esVueloIvao Then
                MsgBox("EXCEPCION AL CONECTAR CON IVAO, PARA ENVIAR REPORTE: " & ex.ToString, MsgBoxStyle.Critical)
            Else
                MsgBox("EXCEPCION AL CONECTAR CON VATSIM, PARA ENVIAR REPORTE: " & ex.ToString, MsgBoxStyle.Critical)
            End If
            Return
        End Try
        'Try
        '    Me.WebBrowser.Navigate(url)
        '    Me.WebBrowser.Dispose()
        'Catch ex As Exception
        '    If esVueloIvao Then
        '        MsgBox("EXCEPCION AL CONECTAR CON IVAO, PARA ENVIAR REPORTE: " & ex.ToString, MsgBoxStyle.Critical)
        '    Else
        '        MsgBox("EXCEPCION AL CONECTAR CON VATSIM, PARA ENVIAR REPORTE: " & ex.ToString, MsgBoxStyle.Critical)
        '    End If
        'End Try

        enviadoIvao = True

    End Sub


    'sUrl = 
End Class